#ifndef _DX8_SURFACE_H_
#define _DX8_SURFACE_H_

#include <d3d8.h>
#include "graphics/surface.h"

class Dx8Surface : public Surface
{
public:
	/// static constructor
	static res::ResourceFile*	CreateImage();
	/// register the valid extensions to our constructors
	static void				RegisterFormats();

	/// set the surface as a texture to the stage
	virtual bool			SetTextureStage(unsigned int _TexStage);

	//virtual void			StretchBlitOnto(Surface* pSurf, const math::Vec2& Offset, const math::Vec2& Size);

	virtual AlphaMask*		GenerateMask();
	virtual COLOR*			GetPixels();		// gets the top-level surface
	virtual float*			GetColors();		// gets the top-level surface as quintuples

	// accessors
    LPDIRECT3DCUBETEXTURE8  GetCubemap() const { return m_Texture.pCubemap; };
    LPDIRECT3DTEXTURE8      GetTexture() const { return m_Texture.pTexture; };
	void					CopyOntoSource(D3DLOCKED_RECT* pRect,int Width, int Height,  int OffsetX, int OffsetY);
	static	Dx8Surface*		FromTexture(LPDIRECT3DTEXTURE8 pTex, int width, int height);
	virtual void			InitTexture();
	virtual	void 			GetTexMemory(unsigned int &TexMem, unsigned int &TexMemComp, unsigned int &TexMemFullC, unsigned int &TexMemPal);
protected:
	// private
	Dx8Surface();
	virtual ~Dx8Surface();
	virtual void			ReleaseResource();
	IDirect3DSurface8*		DDStoSurface();

	bool					TestIsCubemap();


    union
    {
        LPDIRECT3DTEXTURE8      pTexture;
        LPDIRECT3DCUBETEXTURE8  pCubemap;
    }                           m_Texture;
	unsigned int			m_Format;
};

#endif // _DX8_SURFACE_H_